class Solution {
public:
    int uniquePaths(int m, int n) {
        vector<vector<int>> mem(m+1,vector<int>(n+1));
        return dfs(m,n,mem);
    }
    int dfs(int i,int j,vector<vector<int>>& mem)
    {
        if(mem[i][j]!=0)return mem[i][j];

        if(i==0 || j==0)return 0;
        if(i==1 && j==1)
        {
            mem[i][j]=1;
            return 1;
        }

        mem[i][j]=dfs(i-1,j,mem)+dfs(i,j-1,mem);
        return mem[i][j];
    }
};
